package com.list.data.structure;

import java.util.ArrayList;
import java.util.Collection;

public class ShortestPath extends ArrayList<Path> implements Comparable<ShortestPath>{
	private double score;
	
	public void setPathScore(){
        for (Path path : this) {
			this.score += path.getWeight();
		}
    }
    
    public double getPathScore(){
//        this.setPathScore();
        return this.score;
    }
    
    @Override
    public boolean add(Path path) {
    	this.score += path.getWeight();
    	return super.add(path);
    }
    
    @Override
    public boolean addAll(Collection<? extends Path> paths) {
    	for (Path path : paths) {
			this.score += path.getWeight();
		}
    	return super.addAll(paths);
    }
    
    public boolean insert(Path path) {
    	return super.add(path);
    }
    
    public boolean insertALL(Collection<? extends Path> paths) {
    	return super.addAll(paths);
    }
    
    @Override
    public int compareTo(ShortestPath path) {
    	return Double.compare(this.getPathScore(), path.getPathScore());
    }
    
    @Override        
    public String toString() {
        StringBuffer sb = new StringBuffer();
                
        for (Path path : this) {
			sb.append(path.toString());
		}
//        sb.append("\n");
        return sb.toString();
    }

}
